export class TableArgs {
  constructor (state, warnType) {
    const type = warnType + `Table`
    const filterType = {
      'AutoAttack': ['athreaten_level', 'aconclusion', 'ahandle_status'],
      'PerAttack': ['athreaten_level', 'aconclusion', 'ahandle_status']
      // 'PerAttack': ['athreaten_level', 'aconclusion']
    }
    this.filters = {}
    for (let fi of filterType[warnType].values()) {
      this.filters[fi] = state[type].allocation.filters[fi].length > 0 ? state[type].allocation.filters[fi] : []
    }
    this.search = {
      value: state[type].allocation.search.value
    }
    this.sorter = {
      field: state[type].allocation.sorter.field,
      order: state[type].allocation.sorter.order
    }
    this.pagination = {
      current: state[type].allocation.pagination.current,
      pageSize: state[type].allocation.pagination.pageSize
    }
    this.dict = {

    }
    if (!this.search.value) {
      try {
        if (this.hasOwnProperty('search')) {
          delete this.search
        }
      } catch (e) {
        throw new Error(`delete property search error in warnings`)
      }
    }
    if ((!this.sorter.field) || (!this.sorter.order)) {
      try {
        if (this.hasOwnProperty('sorter')) {
          delete this.sorter
        }
      } catch (e) {
        throw new Error(`delete property sorter error in warnings`)
      }
    }
    if ((this.filters) && (this.filters !== {})) {
      for (let i in this.filters) {
        if (this.filters[i].length === 0) {
          delete this.filters[i]
          try {
            if (this.filters.hasOwnProperty(i)) {
              delete this.filters[i]
            }
          } catch (e) {
            throw new Error(`delete property filters.property error in warnings`)
          }
        }
      }
    }
    if (!this.filters) {
      try {
        if (this.hasOwnProperty('filters')) {
          delete this.filters
        }
      } catch (e) {
        throw new Error(`delete property filters error in warnings`)
      }
    }
  }
}
